﻿using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using WPTrek.Data;
using WPTrek.Gui.Controllers;
using WPTrek.Gui.Services;
using WPTrek.Gui.ViewModels;

namespace WPTrek.Gui
{
    public class ModuleInit : IModule
    {
        public ModuleInit(IUnityContainer container, IEventAggregator eventAggregator, IRegionManager regionManager)
        {
            this.container = container;
            this.eventAggregator = eventAggregator;
            this.regionManager = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            var factory = new UniverseFactory();

            /*
             * Only one instance of universe is allowed
             */
            container.RegisterInstance<IUniverse>(factory.Create());

            container.RegisterType<IDataService, DataService>();
            container.RegisterType<IMenuViewModel, MenuViewModel>();
            container.RegisterType<IGameViewModel, GameViewModel>();
            container.RegisterType<IWorldBuilderViewModel, WorldBuilderViewModel>();

            controller = container.Resolve<GuiController>();
        }

        #endregion

        private IUnityContainer container;
        private IEventAggregator eventAggregator;
        private IRegionManager regionManager;

        private GuiController controller;
    }
}
